﻿using Enyim.Caching;
using Ayatta.Contract;
using System.Web.Mvc;
using System.Collections.Specialized;

namespace Web.Pay.Controllers
{
    public class NotifyController : PayBaseController
    {

        public NotifyController(ILogService logService, IBaseService baseService, IExtraService extraService, IStoreService storeService, IOrderService orderService, IGameService gameService, IAuctionService auctionService, IPassportService passportService, IPaymentService paymentService, IMemcachedClient memcachedClient)
            : base(logService, baseService, extraService, storeService, orderService, gameService, auctionService, passportService, paymentService, memcachedClient)
        {
        }

        public string Index(string param)
        {
            return string.Empty;
        }

        /// <summary>
        /// 银联支付通知
        /// </summary>
        /// <returns></returns>
        public ActionResult ChinaPay()
        {
            var pay = GetOnlinePay(1);
            var result = pay.NotityHandler(Request.QueryString);
            if (!result.Status)
            {
                //通知失败 log
                var extra = result.Extra as NameValueCollection;
                return new HttpStatusCodeResult(500);
            }
            return new HttpStatusCodeResult(200);
        }

        /// <summary>
        /// 财富通支付通知
        /// </summary>
        /// <returns></returns>
        public ActionResult TenPay()
        {
            var pay = GetOnlinePay(2);
            var result = pay.NotityHandler(Request.QueryString);
            if (!result.Status)
            {
                //通知失败 log
                var extra = result.Extra as NameValueCollection;
            }
            return Content(result.Data.Token);
        }

        /// <summary>
        /// 支付宝支付通知
        /// </summary>
        /// <returns></returns>
        public ActionResult AliPay()
        {
            var pay = GetOnlinePay(3);
            var result = pay.NotityHandler(Request.Form);
            if (!result.Status)
            {
                //通知失败 log
                var extra = result.Extra as NameValueCollection;
            }
            return Content(result.Data.Token);
        }
    }
}
